USE [CustomersSuppliers]
/****** Object:  StoredProcedure [dbo].[Jobs-Insert]    Script Date: [[20120914064956]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120914064956]]
-- Description:	Insert record into table [dbo].[Jobs]
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[Jobs-Insert]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[Jobs-Insert]*/
GO
-- =============================================
Create PROCEDURE [dbo].[Jobs-Insert]
	/*@Job_RowNumber int =Null OUTPUT , 
	@Job_ID uniqueidentifier =Null  , 
	@Job_Code varchar(50) =Null  , 
	@Job_NameAr varchar(300) =Null  , 
	@Job_NameEn varchar(300) =Null  , 
	@Job_Notes varchar(max) =Null  , 
	@Job_Search varchar(max) =Null  , 
	@Job_TimeStamp timestamp =Null OUTPUT*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	INSERT  INTO [dbo].[Jobs](/*[Job_ID], [Job_Code], [Job_NameAr], [Job_NameEn], [Job_Notes], [Job_Search]*/)
	VALUES     (/*@Job_ID, @Job_Code, @Job_NameAr, @Job_NameEn, @Job_Notes, @Job_Search*/)

	/*SELECT @Job_RowNumber = [Job_RowNumber], @Job_TimeStamp = [Job_TimeStamp]
    FROM [dbo].[Jobs]
    WHERE  ( [Job_ID] =@Job_ID )
	AND  ( [Job_Code] =@Job_Code )
	AND  ( [Job_NameAr] =@Job_NameAr )
	AND  ( [Job_NameEn] =@Job_NameEn )
	AND  ( [Job_Notes] =@Job_Notes )
	AND  ( [Job_Search] =@Job_Search )*/
END
GO
-- =============================================
USE [CustomersSuppliers]
/****** Object:  StoredProcedure [dbo].[Jobs-update]    Script Date: [[20120914064956]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120914064956]]
-- Description:	Update record in table [dbo].[Jobs]
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[Jobs-update]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[Jobs-update]*/
GO
-- =============================================
Create PROCEDURE [dbo].[Jobs-update]
	/*@Job_RowNumber int =Null OUTPUT , 
	@Job_ID uniqueidentifier =Null  , 
	@Job_Code varchar(50) =Null  , 
	@Job_NameAr varchar(300) =Null  , 
	@Job_NameEn varchar(300) =Null  , 
	@Job_Notes varchar(max) =Null  , 
	@Job_Search varchar(max) =Null  , 
	@Job_TimeStamp timestamp =Null OUTPUT , 
	@OldTimeStamp timeStamp OUTPUT*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	/*SELECT @OldTimeStamp = [Job_TimeStamp]
    FROM [dbo].[Jobs]
    	WHERE ([Job_ID] = @Job_ID)

    IF  @OldTimeStamp = @Job_TimeStamp
    BEGIN*/
		Update [dbo].[Jobs] SET 
		/*[Job_ID] =@Job_ID, 
		[Job_Code] =@Job_Code, 
		[Job_NameAr] =@Job_NameAr, 
		[Job_NameEn] =@Job_NameEn, 
		[Job_Notes] =@Job_Notes, 
		[Job_Search] =@Job_Search*/
		/*WHERE ([Job_ID] = @Job_ID)*/
	/*END*/

	/*SELECT @Job_RowNumber = [Job_RowNumber], @Job_TimeStamp = [Job_TimeStamp]
    FROM [dbo].[Jobs]
	WHERE ([Job_ID] = @Job_ID)*/
END
GO
-- =============================================
USE [CustomersSuppliers]
/****** Object:  StoredProcedure [dbo].[Jobs-Insert-Update]    Script Date: [[20120914064956]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120914064956]]
-- Description:	Insert OR Update record into table [dbo].[Jobs]
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[Jobs-Insert-Update]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[Jobs-Insert-Update]*/
GO
-- =============================================
Create PROCEDURE [dbo].[Jobs-Insert-Update]
	/*@Job_RowNumber int =Null OUTPUT , 
	@Job_ID uniqueidentifier =Null  , 
	@Job_Code varchar(50) =Null  , 
	@Job_NameAr varchar(300) =Null  , 
	@Job_NameEn varchar(300) =Null  , 
	@Job_Notes varchar(max) =Null  , 
	@Job_Search varchar(max) =Null  , 
	@Job_TimeStamp timestamp =Null OUTPUT , 
	@Inserted bit OUTPUT , 
	@OldTimeStamp timeStamp OUTPUT*/ 
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;
	IF NOT EXISTS (SELECT * FROM [dbo].[Jobs] 
					/*WHERE ([Job_ID] = @Job_ID)*/)
	BEGIN
		
		INSERT  INTO [dbo].[Jobs](/*[Job_ID], [Job_Code], [Job_NameAr], [Job_NameEn], [Job_Notes], [Job_Search]*/)
		VALUES     (/*@Job_ID, @Job_Code, @Job_NameAr, @Job_NameEn, @Job_Notes, @Job_Search*/)

		SET /*@*/Inserted=1
	END
	ELSE
	BEGIN
		
		/*SELECT @OldTimeStamp = [Job_TimeStamp]
		FROM [dbo].[Jobs]
    	WHERE ([Job_ID] = @Job_ID)

		IF  @OldTimeStamp = @Job_TimeStamp
		BEGIN*/
			Update [dbo].[Jobs] SET 
			/*[Job_ID] =@Job_ID, 
			[Job_Code] =@Job_Code, 
			[Job_NameAr] =@Job_NameAr, 
			[Job_NameEn] =@Job_NameEn, 
			[Job_Notes] =@Job_Notes, 
			[Job_Search] =@Job_Search*/
			/*WHERE ([Job_ID] = @Job_ID)*/
		/*END*/
		
		SET /*@*/Inserted=0
	END

	/*SELECT @Job_RowNumber = [Job_RowNumber], @Job_TimeStamp = [Job_TimeStamp]
    FROM [dbo].[Jobs]
	WHERE ([Job_ID] = @Job_ID)*/
END
GO
-- =============================================
USE [CustomersSuppliers]
/****** Object:  StoredProcedure [dbo].[Jobs-Delete]    Script Date: [[20120914064956]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120914064956]]
-- Description:	delete records from table [dbo].[Jobs] based on optional Conditions
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[Jobs-Delete]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[Jobs-Delete]*/
GO
-- =============================================
Create PROCEDURE [dbo].[Jobs-Delete]
	/*@Job_RowNumber int =null  , 
	@Job_ID uniqueidentifier =null  , 
	@Job_Code varchar(50) =null  , 
	@Job_NameAr varchar(300) =null  , 
	@Job_NameEn varchar(300) =null  , 
	@Job_Notes varchar(max) =null  , 
	@Job_Search varchar(max) =null  , 
	@Job_TimeStamp timestamp =null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	Delete FROM  [dbo].[Jobs]
	WHERE /*( [Job_RowNumber] = ISNULL(@Job_RowNumber, [Job_RowNumber]) )
	AND ( [Job_ID] = ISNULL(@Job_ID, [Job_ID]) )
	AND ( [Job_Code] like ISNULL(@Job_Code, [Job_Code]) )
	AND ( [Job_NameAr] like ISNULL(@Job_NameAr, [Job_NameAr]) )
	AND ( [Job_NameEn] like ISNULL(@Job_NameEn, [Job_NameEn]) )
	AND ( [Job_Notes] like ISNULL(@Job_Notes, [Job_Notes]) )
	AND ( [Job_Search] like ISNULL(@Job_Search, [Job_Search]) )
	AND ( [Job_TimeStamp] = ISNULL(@Job_TimeStamp, [Job_TimeStamp]) )*/
END
GO
-- =============================================
USE [CustomersSuppliers]
/****** Object:  StoredProcedure [dbo].[Jobs-Select]    Script Date: [[20120914064957]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120914064957]]
-- Description:	select records from table [dbo].[Jobs] based on optional Conditions
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[Jobs-Select]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[Jobs-Select]*/
GO
-- =============================================
Create PROCEDURE [dbo].[Jobs-Select]
	/*@Job_RowNumber int =null  , 
	@Job_ID uniqueidentifier =null  , 
	@Job_Code varchar(50) =null  , 
	@Job_NameAr varchar(300) =null  , 
	@Job_NameEn varchar(300) =null  , 
	@Job_Notes varchar(max) =null  , 
	@Job_Search varchar(max) =null  , 
	@Job_TimeStamp timestamp =null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	SELECT * FROM  [dbo].[Jobs]
	WHERE /*( [Job_RowNumber] = ISNULL(@Job_RowNumber, [Job_RowNumber]) )
	AND ( [Job_ID] = ISNULL(@Job_ID, [Job_ID]) )
	AND ( [Job_Code] like ISNULL(@Job_Code, [Job_Code]) )
	AND ( [Job_NameAr] like ISNULL(@Job_NameAr, [Job_NameAr]) )
	AND ( [Job_NameEn] like ISNULL(@Job_NameEn, [Job_NameEn]) )
	AND ( [Job_Notes] like ISNULL(@Job_Notes, [Job_Notes]) )
	AND ( [Job_Search] like ISNULL(@Job_Search, [Job_Search]) )
	AND ( [Job_TimeStamp] = ISNULL(@Job_TimeStamp, [Job_TimeStamp]) )*/
END
GO
-- =============================================
